<%@page import="com.crm.entity.SupplierUser"%>
<%@page import="java.util.List,java.util.Iterator,com.crm.entity.Supplier" %>

      <% Supplier supplier=(Supplier)request.getAttribute("supplier"); %>

      <%System.out.println("The Supplier List Is: "+supplier);%>
     <script language="javascript">
     $(document).ready(function(){
     	$('.form1').live('click',function(){
   	alert("In Function");
     		
     		var e2=document.getElementById(this.id);
     		
     	   	
     		var div=$("#divisionid").val();
     		alert(div);
     		if(div!=""){
     		var temp=div.split(",");
     		
     		
     		if(temp != null){
     			
     			if(e2.options.length>1){
     			for(var i=0;i<temp.length;i++){
     				if(e2.options.length>i+1){
     				if(e2.options[i+1].value!=temp[i]){
     				var o=document.createElement('option');
     				o.value=temp[i];
     				o.text=temp[i];
     				e2.options.add(o);
     				
     				}
     				}else {
     					var o=document.createElement('option');
         				o.value=temp[i];
         				o.text=temp[i];
         				e2.options.add(o);
     				}
     			}
     			}
     				else{
     					for(var i=0;i<temp.length;i++){
     	    				   	    				
     	    				var o=document.createElement('option');
     	    				o.value=temp[i];
     	    				o.text=temp[i];
     	    				e2.options.add(o);
     	    				
     	    				}
     				}
     	    			
     					
     				}
     		}
     			});
     	});
        function addRow(edituserTable) {
 	
            var table = document.getElementById(edituserTable);
 			var rowCount = table.rows.length;
			var row = table.insertRow(rowCount);
			
			table.setAttribute("bgColor", "#C5E4EB");
		    var cell1 = row.insertCell(0);
		    cell1.innerHTML = rowCount ;
           	cell1.setAttribute("bgColor","#FFFFFF");
           	cell1.setAttribute("align","center");
            
           	
            var cell2 = row.insertCell(1);
            cell2.setAttribute("bgColor","#FFFFFF");
            var element2 = document.createElement("input");
			element2.type = "text";
			element2.name="cperson"+rowCount;
			element2.id="cperson"+rowCount;
			element2.className="user";
			element2.size="15";
            cell2.appendChild(element2);
            
            
           /*  var cell3 = row.insertCell(2);
            cell3.setAttribute("bgColor","#FFFFFF");
            var element3 = document.createElement("input");
			element3.type = "text";
			element3.name="division"+rowCount;
			element3.id="division"+rowCount;
			element3.className="user";
			element3.size="15";
            cell3.appendChild(element3); */
			
			var cell3 = row.insertCell(2);
			cell3.setAttribute("bgColor","#FFFFFF");
			 var element3 = document.createElement("input");
				element3.type = "text";
				element3.name="phone"+rowCount;
				element3.id="phone"+rowCount;
				element3.className="user";
				element3.size="15";
	            cell3.appendChild(element3);
			
			
			 var cell4 = row.insertCell(3);
			
			 cell4.setAttribute("bgColor","#FFFFFF");
			 var element4 = document.createElement("input");
				element4.type = "text";
				element4.name="email"+rowCount;
				element4.id="email"+rowCount;
				element4.className="email";
				element4.size="15";
	            cell4.appendChild(element4);
				
	            document.getElementById('editrowcountid').value=rowCount;
            

        
        }
 
        function deleteRow(edituserTable) {
        	var tbl = document.getElementById(edituserTable);
        	var lastRow = tbl.rows.length;
        	if (lastRow > 2) tbl.deleteRow(lastRow - 1);
        	var table = document.getElementById(edituserTable);
        	var rowCount = table.rows.length;
        	document.getElementById('editrowcountid').value=rowCount-1;
        }
 
       

    </script>
<form name="supplierfrm" action="<%=application.getContextPath()%>/supplier/editsave.do" method="post">
    <div id="work-area2">
      <div class="heading">Edit Supplier</div>
	  
      <div class="boxIFS">
      
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td width="9%" align="left"><input type="hidden" value="<%=supplier.getId()%>" name="supplierId"/></td>
              <td width="17%" align="left">Supplier Name</td>
              <td width="29%" align="left" valign="middle"><label></label> 
                   
                  <input name="sname" type="text" class="form" id="suppnameid" value="<%=supplier.getName()%>"/>
                  
                
                
                 </td>
              <td width="11%" align="left" valign="middle">Website</td>
              <td width="24%" align="left" valign="middle">
              <input name="website" type="text" class="form" id="websiteid" value="<%=supplier.getWebsite()%>"/></td>
              <td width="10%" align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left">Email</td>
              <td align="left" valign="middle"><label>
                <input name="email" type="text" class="form-lowercase" id="emailid" value="<%=supplier.getEmail()%>"/>
                </label>              </td>
              <td align="left" valign="middle">Fax</td>
              <td align="left" valign="middle"><label>
                <input name="fax" type="text" class="form" id="faxid" value="<%=supplier.getFax()%>"/>
                </label>              </td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left">&nbsp;</td>
              <td align="left">Phone Number</td>
              <td align="left" valign="middle"><label>
                <input name="phno" type="text" class="form" id="phnoid" value="<%=supplier.getPhone()%>"/>
                </label>              </td>
              <td align="left" valign="middle">Address</td>
              <td align="left" valign="middle"><label>
                <textarea name="address" class="form" id="addressid"><%=supplier.getAddress()%></textarea>
              </label>              </td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="right"></td>
              <td height="5" align="right"></td>
              <td height="5" align="right" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <%-- <tr>
              <td align="left">&nbsp;</td>
              <td align="left">Divisions</td>
              <td align="left" valign="top"><input name="division" type="text" class="form" id="divisionid" value="<%=supplier.getDivisions()%>"/></td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr> --%>
          </table>
       
      </div>
	   <%System.out.println("Supplier User Is:"+request.getAttribute("supplier-user"));
	   
	   %> 
	  <div class="box2">
	  <table>
	   <tr>
	  <td>
        <table  id="edituserTable" width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#C5E4EB">
          <tr>
            <td width="36" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x">S.No </td>
            <td width="138" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Contact Person</td>
            <%-- <td width="140" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF"> Division</td> --%>
            <td width="162" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"  style="background-repeat:repeat-x bgcolor="#FFFFFF">Phone</td>
            <td width="186" align="center" valign="middle" background="<%=application.getContextPath()%>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Email</td>
          </tr>
          <%
          List<SupplierUser> lsu=(List<SupplierUser>)request.getAttribute("supplier-user");
          System.out.println("List Size Is:"+lsu.size());
          for(int i=0;i<lsu.size();i++){
        	  System.out.println("I Value Is:"+i);
          %>
          <tr>
          <input type="hidden" name="supId<%=i+1%>" value="<%=lsu.get(i).getId()%>"/>
            <td align="center" bgcolor="#FFFFFF"><%=i+1 %></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="cperson<%=i+1%>" type="text" size="5" value="<%=lsu.get(i).getUsername()%>"/></td>
           <%--  <td align="left" valign="top" bgcolor="#FFFFFF">
            
                
                <select name="division<%=i+1 %>" class="form1"   style="border: 0px;" id="division<%=i+1 %>" >
                 <option value="<%=lsu.get(i).getDivision()%>"><%= lsu.get(i).getDivision()%></option>
                </select>
                
                </td> --%>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="phone<%=i+1%>" type="text" size="5" value="<%=lsu.get(i).getPhn()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="email<%=i+1%>" class="email" type="text" size="5" value="<%=lsu.get(i).getEmail()%>"/></td>
          </tr>
          <%
          } %>
         <input name="editrowcount" type="hidden" id="editrowcountid" value="<%=lsu.size()%>"/>
        </table>
                </td>
        </tr>
        <tr>
                <td align="left" valign="top"><div class="buttonleft"><a href="javascript:addRow('edituserTable')" >Add Row</a></div> 
                                   <div class="buttonleft"><a href="javascript:deleteRow('edituserTable')" >Delete Row</a></div>
                                    
                   </td>
              </tr>
              <tr>
                <td> 
                 <div class="box2">
	    			<div class="buttton-main">	    				
	    				<div class="button"><a href="<%=application.getContextPath()%>/supplier//open.do">New</a></div>
	    				<div class="button">Clear</div>
	    				<a href=""><input type="image" class="button" value="Save" onclick="javascript:return validate();"/></a>
	    			</div>
	  			</div>
	  </td>
              </tr>
              </table>
      </div>
	  
	  
    </div>
    </form>